package sort.quick;

/**
 * @author justnow
 * Created on 2020-09-19
 * Description
 */
public class QuickSorted_TIMES02 {
    public void quickSort(int nums[], int low, int high) {
        if (low < high) {
            int pivotkey = partition(nums, low, high);
            quickSort(nums, low, pivotkey - 1);
            quickSort(nums, pivotkey + 1, high);
        }
    }

    private int partition(int[] nums, int low, int high) {
        int pivotkey = nums[low];
        while (low < high) {
            while (low < high && nums[high] >= pivotkey) {
                high--;
            }
            nums[low] = nums[high];
            while (low < high && nums[low] <= pivotkey) {
                low++;
            }
            nums[high] = nums[low];
        }
        nums[low] = pivotkey;
        return low;
    }

    public static void main(String[] args) {
        int[] demo = {1, 10, 3, 6, 19, 10, 30};
        QuickSorted_TIMES02 quickSorted_times02 = new QuickSorted_TIMES02();
        quickSorted_times02.quickSort(demo, 0, 5);
        for (int i : demo) {
            System.out.println(i);
        }
    }

}


